#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    timer = new QTimer(this);
    ui->setupUi(this);
    ui->label->setBuddy(ui->radioButton);

    ui->lcdNumber->display(10);
    connect(timer, &QTimer::timeout, this, &Widget::countDown);

    ui->progressBar->setValue(0);
    timer->start(1000);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::countDown()
{
    //放在这里要加1的原因：进度条的值被设置后，紧接着计时器上的数就-1了，不加1就会慢1拍；
    //qDebug() << 10 - ui->lcdNumber->intValue() + 1 << endl;
    //ui->progressBar->setValue((10 - ui->lcdNumber->intValue() + 1) * 10);
    if(ui->lcdNumber->intValue() > 0)
    {
        ui->lcdNumber->display(ui->lcdNumber->intValue() - 1);
        ui->progressBar->setValue((10 - ui->lcdNumber->intValue()) * 10);
        //放在这紧接着计时器的更改，就不用加1了！
    }
    else
    {
        timer->stop();
    }
}


void Widget::on_progressBar_valueChanged(int value)
{
    (void)value;
}

void Widget::on_calendarWidget_clicked(const QDate &date)
{
    ui->datelabel->setText(date.toString());
}
